# -*- coding: utf-8 -*-
from django.http import JsonResponse
from django.contrib.auth.decorators import login_required, user_passes_test
from accounts.models import StudentSurvey
from django.shortcuts import get_object_or_404


def is_superuser(user):
    return user.is_superuser


@login_required
@user_passes_test(is_superuser, login_url='/login/')
def get_data_detail(request, record_id):
    """获取数据详情"""
    record = get_object_or_404(StudentSurvey, id=record_id)

    # 将对象转换为字典
    data = {
        'id': record.id,
        'gender': record.gender,
        'gender_display': record.get_gender_display(),
        'age': record.age,
        'friends': record.friends,
        'gradyear': record.gradyear,
        'created_at': record.created_at.strftime('%Y-%m-%d %H:%M:%S'),
        'updated_at': record.updated_at.strftime('%Y-%m-%d %H:%M:%S'),

        # 运动兴趣
        'basketball': record.basketball,
        'football': record.football,
        'soccer': record.soccer,
        'softball': record.softball,
        'volleyball': record.volleyball,
        'swimming': record.swimming,
        'cheerleading': record.cheerleading,

        # 时尚与外表
        'hair': record.hair,
        'dress': record.dress,
        'blonde': record.blonde,
        'mall': record.mall,
        'shopping': record.shopping,
        'clothes': record.clothes,
        'hollister': record.hollister,
        'abercrombie': record.abercrombie,

        # 个性特征
        'cute': record.cute,
        'sexy': record.sexy,
        'hot': record.hot,
        'kissed': record.kissed,

        # 风险行为
        'drunk': record.drunk,
        'drugs': record.drugs,
        'death': record.death,
        'die': record.die,
    }

    return JsonResponse(data)
